package com.atguigu.gmall.user.rpc;

import com.atguigu.gmall.cart.vo.UserAuth;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.UserAuthUtil;
import com.atguigu.gmall.user.entity.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lfy
 * @Description
 * @create 2023-08-01 15:27
 */
@RestController
@RequestMapping("/api/inner/user")
public class UserRpcController {


    @Autowired
    UserAddressService userAddressService;


    /**
     * 查询用户收货地址列表
     * @return
     */
    @GetMapping("/addresses")
    public Result<List<UserAddress>> getUserAddresses(){

        UserAuth auth = UserAuthUtil.getUserAuth();

        List<UserAddress> list = userAddressService.lambdaQuery()
                .eq(UserAddress::getUserId, Long.parseLong(auth.getUserid()))
                .list();

        return Result.ok(list);
    }
}
